package com.lai.lai.controller;

import com.lai.lai.entity.Area;
import com.lai.lai.utils.ResultResponse;
import com.lai.lai.service.AreaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.lang.Nullable;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * @Author lmx
 * @Date 2021/4/27 20:48
 * @Version 1.0
 */
@RestController
@RequestMapping("/admin")
public class AreaController {

    @Autowired
    private AreaService areaService;

    @RequestMapping(value = "listarea",method = RequestMethod.GET)
    private ResultResponse<List<Area>> listArea() {

        return areaService.queryArea();
    }

    @RequestMapping(value = "getareabyid",method = RequestMethod.GET)
    private ResultResponse<Area> getAreaById(Integer areaId){
        return areaService.queryAreaById(areaId);
    }

    @RequestMapping(value = "addarea",method = RequestMethod.POST)
    private ResultResponse<Area> addArea(String areaName, Integer priority){
        return areaService.insertArea(areaName,priority);
    }

    @RequestMapping(value = "updatearea",method = RequestMethod.POST)
    private ResultResponse<Area> updateArea(@NotNull Integer areaId,@Nullable String areaName, @Nullable Integer priority){
        return areaService.updateArea(areaId,areaName,priority);
    }

    @RequestMapping(value = "deletearea",method = RequestMethod.GET)
    private ResultResponse<Integer> deleteArea(Integer areaId){
        return areaService.deleteArea(areaId);
    }
}
